<!DOCTYPE html>
<!--
  ~  +----------------------------------------------------------------------
  ~  | 草帽支付系统 [ WE CAN DO IT JUST THINK ]
  ~  +----------------------------------------------------------------------
  ~  | Copyright (c) 2018 http://www.iredcap.cn All rights reserved.
  ~  +----------------------------------------------------------------------
  ~  | Licensed ( https://www.apache.org/licenses/LICENSE-2.0 )
  ~  +----------------------------------------------------------------------
  ~  | Author: Brian Waring <BrianWaring98@gmail.com>
  ~  +----------------------------------------------------------------------
  -->

<html>
<head>
    <meta charset="utf-8">
    <title>小红帽科技|草帽聚合支付 - 后台管理 - 文章添加</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="__ADMIN__/layui/css/layui.css" media="all">
</head>
<body>

<div class="layui-form" lay-filter="app-article-form-list" id="app-article-form-list" style="padding: 20px 30px 0 0;">
    <div class="layui-form-item">
        <label class="layui-form-label">文章标题</label>
        <div class="layui-input-block">
            <input type="text" name="title" lay-verify="required" value="" placeholder="请输入文章标题" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">发布人</label>
        <div class="layui-input-inline">
            <input type="text" name="author" lay-verify="required" value="" placeholder="请输入发布人" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">文章描述</label>
        <div class="layui-input-block">
            <input type="text" name="describe" lay-verify="required" value="" placeholder="请输入文章描述" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">文章内容</label>
        <div class="layui-input-block">
            <textarea name="content" lay-verify="required" id="content_editor" style="width: 400px; height: 150px;" autocomplete="off" class="layui-textarea"></textarea>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">发布状态</label>
        <div class="layui-input-inline">
            <input type="checkbox" lay-verify="required" lay-filter="status" name="status" value="1" lay-skin="switch" lay-text="发布|等待中">
        </div>
    </div>
    <div class="layui-form-item layui-hide">
        <input type="button" lay-submit lay-filter="app-article-form-submit" id="app-article-form-submit" value="确认添加">
        <input type="button" lay-submit lay-filter="app-article-form-edit" id="app-article-form-edit" value="确认编辑">
    </div>
</div>

<script src="__ADMIN__/layui/layui.js"></script>
<script>
    layui.config({
        base: '__ADMIN__/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'form','layedit'], function(){
        var $ = layui.$,
            layedit = layui.layedit,
            form = layui.form;
        //处理上传接口
        layedit.set({
            uploadImage: {
                url: 'upload' //接口url
                ,type: 'post' //默认post//自定义响应字段
                ,response: {
                    statusName: 'code' //数据状态的字段名称
                    ,statusCode: 1 //数据状态一切正常的状态码
                    ,msgName: 'msg' //状态信息的字段名称
                    ,dataName: 'data' //数据详情的字段名称
                },
            }
        });
        //创建一个编辑器
        layedit.build('content_editor', {
            tool: [

                'strong' //加粗
                , 'italic' //斜体
                , 'underline' //下划线
                , 'del' //删除线
                , '|' //分割线
                , 'left' //左对齐
                , 'center' //居中对齐
                , 'right' //右对齐
                , 'link' //超链接
                , 'unlink' //清除链接
                , 'face' //插入表情
                , 'image' //插入图片
            ],
            height: 300
        });
        //监听提交
        form.on('submit(app-article-form-submit)', function(data){
            var field = data.field; //获取提交的字段
            var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
            //提交 Ajax 成功后，关闭当前弹层并重载表格
            //这里是提交
            $.post("/article/add",field,function (res) {
                if (res.code == 1){
                    parent.layui.table.reload('app-article-list'); //重载表格
                    parent.layer.close(index); //再执行关闭
                }else {
                    layer.msg(res.msg);
                }
            })
        });
    })
</script>
</body>
</html>